Skip to content

fix(rust): bound repaired compressed text before allocation - #281

Draft
lan17 wants to merge 2 commits into
mainfrom
fix/rust-text-output-bound
Draft

lan17 wants to merge 2 commits into
mainfrom
fix/rust-text-output-bound

Conversation

@lan17

@lan17 lan17 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Problem

A bounded resource test found that a 6,151-byte compressed text envelope can decode to 192 MiB of 0xFF and then allocate 576 MiB of repaired UTF-8. The raw bytes fit the 512 MiB read ceiling, but the repaired text does not.

The same case reaches the reader through a tracked, remote-only get_or_load with disable_compression(). That option controls new writes, not reads.

Change

Bug fix under the X02 native resource boundary. No design record is needed: no portable contract, public API, cache-value policy, key or frame format changes.

  • Count UTF-8 replacement growth before allocating repaired text, and reject output above MAX_DECOMPRESSED_BYTES.
  • Keep valid UTF-8 on one validation pass and one copy. Allocate accepted malformed text at its exact repaired length.
  • Preserve the caller's raw-decompression limit: a limit of 1 still accepts one 0xFF and returns the three-byte replacement character.
  • Return ReadOverLimit and the original marked bytes. The default JSON codec rejects these bytes, so the cache loads the source and writes its result. A custom codec that accepts the raw bytes keeps the existing fallback behavior.
  • Add exact-boundary tests, a direct allocation regression, and a full tracked-read regression with compression disabled.

This is independent of the Go change in PR 276.

Ports

Port Status
TypeScript N/A: unchanged in this Rust resource fix
Go N/A: separate change in PR 276
Rust done
Python N/A: unchanged in this Rust resource fix

Validation

Head: 7c53162e3da39427930b6b6a9302f29c9eaa674d

Only commit credit trailers were removed after c1ac0ac1fd13ea46aab890910a02fc12b2f72a39; the complete file tree is identical.

  • make check-rust and make audit at c1ac0ac1fd13ea46aab890910a02fc12b2f72a39: pass, including formatting, both clippy lanes, native tests and committed conformance histories. These local results cover the identical current file tree.
  • Both resource regressions fail on base 22c1f502ddb5f27419faf5caa528d9ea3a9c92e4: the reader reports Decompressed instead of ReadOverLimit.
  • Bounded release-mode runs of the matched fixture pass with the fix. Each child has a 2 GiB address-space limit, 30 CPU-second limit and 60-second wall timeout.
Path Base peak RSS Fixed peak RSS Result
Direct decompression 790,352 KiB 201,064 KiB Original bytes and ReadOverLimit
Tracked read, compression disabled 790,816 KiB 201,460 KiB ReadOverLimit, one source call, one write
  • The allocation counter also passes on this file tree. An allocate-then-check negative control fails it with 1,946,163,207 allocated bytes, despite returning the expected outcome.

  • No changed file is named by either mutation catalog, so the required hosted tier is Replay.

  • Hosted PR CI at 7c53162e3da39427930b6b6a9302f29c9eaa674d: pass, including native and wire checks, formal smoke and differential checks, documentation build and CodeQL. Only documentation deployment was skipped.

  • formal-full.yaml, mode replay, run 43386430953 at 7c53162e3da39427930b6b6a9302f29c9eaa674d: pass. Generation, symbolic verification, all four complete language replays and the final aggregate passed. Model, mutation and exploration jobs were skipped as required by Replay mode.

  • Read-only independent review of the identical file tree found no unresolved findings across correctness, tests, simplicity, architecture, contracts, security, reliability, performance and full-flow review. The rollout safety review found no blocker.

  • An independent bounded repeat confirmed the exact fixture, raw limits of 0 and 1, and the tracked read with compression disabled. The tracked read called the source once and wrote once; its peak RSS fell from 789,880 KiB to 200,436 KiB. This is evidence for the tested fixture, not a total process-memory ceiling.

Not run locally: Redis/Valkey/Cluster integration; hosted PR CI passed that lane.

Required hosted lanes not run: none.

Follow-ups

None.

@codecov-commenter

codecov-commenter commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.82%. Comparing base (22c1f50) to head (7c53162).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #281      +/-   ##
==========================================
+ Coverage   94.76%   94.82%   +0.06%     
==========================================
  Files          84       84              
  Lines       13168    13230      +62     
  Branches      805      805              
==========================================
+ Hits        12479    12546      +67     
+ Misses        623      618       -5     
  Partials       66       66              
Flag Coverage Δ
go 93.86% <ø> (ø)
python 93.60% <ø> (ø)
rust 94.89% <100.00%> (+0.11%) ⬆️
typescript 97.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Count UTF-8 replacement output before allocating it and enforce the existing global decompression ceiling. Keep per-call limits on raw decoded bytes and preserve the original envelope on rejection.
Measure Rust allocation bytes during the direct decompression regression. An unrestricted repair followed by a size check exceeds the budget even though it returns the expected outcome.
@lan17
lan17 force-pushed the fix/rust-text-output-bound branch from c1ac0ac to 7c53162 Compare November 13, 2026 07:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants